import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.text.*;

public class T9Main {
  public static void main(String[] args) {
    JFrame f = new JFrame("T9 Predictor Keyboard");
    JPanel upperPanel = new JPanel();
    JPanel lowerPanel = new JPanel();
    //f.getContentPane().add(upperPanel, "North");
    f.getContentPane().add(lowerPanel, "South");

    //upperPanel.add(new JTextArea(content));
    //upperPanel.add(new JTextArea(content, 6, 10));
    //upperPanel.add(new JTextArea(content, 3, 8));

    //lowerPanel.add(new JScrollPane(new JTextArea(content)));
			
    //myArea.getDocument().addDocumentListener(myListener);
	
    JTextArea ta = new JTextArea(content, 10, 40);
    ta.setLineWrap(true);
    ta.setWrapStyleWord(true);

		Document doc;
		final int MAX_CHARACTERS = 300;
		Document styledDoc = ta.getDocument();
		if (styledDoc instanceof AbstractDocument) {
				doc = (AbstractDocument)styledDoc;
				doc.setDocumentFilter(new DocumentFilter() {
				public void insertString(FilterBypass fb, int offs, String str, AttributeSet a)
					throws BadLocationException {
					if ((fb.getDocument().getLength() + str.length()) <= 300)
						super.insertString(fb, offs, str, a);
					else
						Toolkit.getDefaultToolkit().beep();
					}
				});
		}

    lowerPanel.add(new JScrollPane(ta));

    /* ta = new JTextArea(content, 6, 8);
    ta.setLineWrap(true);
    ta.setWrapStyleWord(true);
    lowerPanel.add(new JScrollPane(ta)); */

    f.pack();
    f.setVisible(true);
  }

  static String content = "Here men from the planet Earth\n"
      + "first set foot upon the Moon,\n" + "July 1969, AD.\n"
      + "We came in peace for all mankind.";
}


